#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

typedef int BTDataType;
typedef struct BinaryTreeNode
{
	BTDataType data;
	struct BinaryTreeNode* left;
	struct BinaryTreeNode* right;
}BTNode;

BTNode* BuyNode(BTDataType x)
{
	BTNode* node = (BTNode*)malloc(sizeof(BTNode));
	if (node == NULL)
	{
		perror("malloc");
		return NULL;
	}

	node->data = x;
	node->left = NULL;
	node->right = NULL;

	return node;
}

void PerOrder(BTNode* root)
{
	if (root == NULL)
		return NULL;

	printf("%d ", root->data);
	PerOrder(root->left);
	PerOrder(root->right);
}

void InOrder(BTNode* root)
{
	if (root == NULL)
		return NULL;

	PerOrder(root->left);
	printf("%d ", root->data);
	PerOrder(root->right);
}

void PostOrder(BTNode* root)
{
	if (root == NULL)
		return NULL;

	PerOrder(root->left);
	PerOrder(root->right);
	printf("%d ", root->data);
}

int main()
{
	BTNode* node1 = BuyNode(1);
	BTNode* node2 = BuyNode(2);
	BTNode* node3 = BuyNode(3);
	BTNode* node4 = BuyNode(4);
	BTNode* node5 = BuyNode(5);
	BTNode* node6 = BuyNode(6);

	node1->left = node2;
	node1->right = node4;
	node2->left = node3;
	node4->left = node5;
	node4->right = node6;

	PerOrder(node1);
	printf("\n");
	InOrder(node1);
	printf("\n");
	PostOrder(node1);
	printf("\n");
	return 0;
}